import 'package:flutter/material.dart';

class PublisGridView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    List<String> titleList = ["资料查询", "消息处理", "直击现场", "视频会议"];
    List<String> imagelist = [
      "image/img_select.png",
      "image/img_msg.png",
      "image/img_tuiliu.png",
      "image/img_huiyi.png"
    ];

    return GridView.builder(
      padding: const EdgeInsets.all(10.0),
      itemCount: titleList.length,
      itemBuilder: (BuildContext context, int index) {
        //Widget Function(BuildContext context, int index)
        return getGridViewItem(titleList[index], imagelist[index]);
      },
      //SliverGridDelegateWithFixedCrossAxisCount 构建一个横轴固定数量Widget
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
        //横轴元素个数
          crossAxisCount: 2,
          //纵轴间距
          mainAxisSpacing: 10.0,
          //横轴间距
          crossAxisSpacing: 10.0,
          //子组件宽高长度比例
          childAspectRatio: 1.4),
    );
  }

  Widget getGridViewItem(String title, String imageName) {
    return InkWell(
      onTap: () {},
      child: Card(
        elevation: 1.0, //设置阴影
        shape: const RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(10.0))), //设置圆角
        child: Column(
          children: <Widget>[
            Row(
              children: <Widget>[
                Expanded(
                  child: Container(
                    padding: const EdgeInsets.only(top: 20),
                    alignment: Alignment.center,
                    child: Image.asset(
                      imageName,
                      width: 50,
                      height: 50,
                      fit: BoxFit.cover,
                    ),
                  ),
                )
              ],
            ),
            Row(
              children: <Widget>[
                Expanded(
                  child: Container(
                      padding: EdgeInsets.only(top: 8),
                      alignment: Alignment.center,
                      child: Text(
                        title,
                        style: const TextStyle(
                            color: Colors.grey, fontSize: 18, height: 1.2),
                      )),
                )
              ],
            )
          ],
        ),
      ),
    );
  }
}
